using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using WebControls;
using BusinessLayer;

public partial class Utils_Photos : SFPage
{
    protected string GeneratePhotoUrlPreview(object obj)
    {
        Crypto c = new Crypto();
        return "~/Handlers/Image.ashx?Url=" + c.EncryptURL(obj.ToString()) + "&Width=550";
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            Crypto c = new Crypto();
            DataRow dr = ((DataTable)Session["DataTablePhotos"]).Select("PhotoId=" + c.DecryptURL(Request.QueryString["Photo"]))[0];
            int index = ((DataTable)Session["DataTablePhotos"]).Rows.IndexOf(dr);
            btnPrev.Visible = (index > 0);
            btnPrev1.Visible = btnPrev.Visible;
            btnNext.Visible = (index < ((DataTable)Session["DataTablePhotos"]).Rows.Count - 1);
            btnNext1.Visible = btnNext.Visible;
            imgPreview.Src = GeneratePhotoUrlPreview(dr["PhotoPath"]);
            lblPhotoTop.Text = Convert.ToDateTime(dr["DatePictureTaken"]).ToShortDateString() + " - " + dr["PhotoName"].ToString();
            lblPhotoBottom.Text = dr["PhotoDescription"].ToString();
            ViewState["index"] = index;
            pnlImagePreview.Width = 700;
            pnlImagePreview.Height = 700;
            this.Title = dr["PhotoDescription"].ToString();
        }
    }
    protected void btnNext_Click(object sender, EventArgs e)
    {
        int index = Convert.ToInt32(ViewState["index"]) + 1;
        btnPrev.Visible = (index > 0);
        btnPrev1.Visible = btnPrev.Visible;
        btnNext.Visible = (index < ((DataTable)Session["DataTablePhotos"]).Rows.Count - 1);
        btnNext1.Visible = btnNext.Visible;
        imgPreview.Src = GeneratePhotoUrlPreview(((DataTable)Session["DataTablePhotos"]).Rows[index]["PhotoPath"]);
        lblPhotoTop.Text = Convert.ToDateTime(((DataTable)Session["DataTablePhotos"]).Rows[index]["DatePictureTaken"]).ToShortDateString() + " - " + ((DataTable)Session["DataTablePhotos"]).Rows[index]["PhotoName"].ToString();
        lblPhotoBottom.Text = ((DataTable)Session["DataTablePhotos"]).Rows[index]["PhotoDescription"].ToString();
        ViewState["index"] = index;
        pnlImagePreview.Width = 700;
        pnlImagePreview.Height = 700;
        this.Title = lblPhotoBottom.Text;
    }
    protected void btnPrev_Click(object sender, EventArgs e)
    {
        int index = Convert.ToInt32(ViewState["index"]) - 1;
        btnPrev.Visible = (index > 0);
        btnPrev1.Visible = btnPrev.Visible;
        btnNext.Visible = (index < ((DataTable)Session["DataTablePhotos"]).Rows.Count - 1);
        btnNext1.Visible = btnNext.Visible;
        imgPreview.Src = GeneratePhotoUrlPreview(((DataTable)Session["DataTablePhotos"]).Rows[index]["PhotoPath"]);
        lblPhotoTop.Text = Convert.ToDateTime(((DataTable)Session["DataTablePhotos"]).Rows[index]["DatePictureTaken"]).ToShortDateString() + " - " + ((DataTable)Session["DataTablePhotos"]).Rows[index]["PhotoName"].ToString();
        lblPhotoBottom.Text = ((DataTable)Session["DataTablePhotos"]).Rows[index]["PhotoDescription"].ToString();
        ViewState["index"] = index;
        pnlImagePreview.Width = 700;
        pnlImagePreview.Height = 700;
        this.Title = lblPhotoBottom.Text;
    }
}
